package com.yvon.grpc.client.service;

import com.yvon.grpc.api.HelloRequest;
import com.yvon.grpc.api.HelloWorldGrpc;
import io.grpc.ManagedChannel;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

/**
 * @author : wangyufeng
 * @since : 2021-10-19
 */
@Service
public class HelloWorldClientService {

    private HelloWorldGrpc.HelloWorldBlockingStub stub;

    @Autowired
    private ManagedChannel managedChannel;

    @PostConstruct
    private void init() {
        stub = HelloWorldGrpc.newBlockingStub(managedChannel);
    }


    public String rpc(String message) {
        HelloRequest request = HelloRequest.newBuilder().setMessage(message).build();
        return stub.hello(request).getResponse();
    }
}
